package com.aspose.cells;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Calendar;

class ztm {
   public static int a(Cells var0, ResultSet var1, int var2, int var3, int var4, int var5, boolean var6) throws SQLException {
      return a(var0, var1, var2, var3, var4, var5, var6, (String)null, false);
   }

   public static int a(Cells var0, ResultSet var1, String var2, int var3, int var4, boolean var5) throws SQLException {
      int[] var6 = CellsHelper.cellNameToIndex(var2);
      return a(var0, var1, var6[0], var6[1], var3, var4, var5);
   }

   public static int a(Cells var0, ResultSet var1, int var2, int var3, boolean var4) throws SQLException {
      return a(var0, var1, var2, var3, -1, -1, var4);
   }

   public static int a(Cells var0, ResultSet var1, String var2, boolean var3) throws SQLException {
      return a(var0, var1, var2, -1, -1, var3);
   }

   public static int a(Cells var0, ResultSet var1, int var2, int var3, int var4, int var5, boolean var6, String var7, boolean var8) throws SQLException {
      if (var4 != 0 && var5 != 0) {
         zakq.a(var2);
         zakq.b(var3);
         ResultSetMetaData var9 = var1.getMetaData();
         if (var5 < 0) {
            var5 = var9.getColumnCount();
         } else {
            var5 = Math.min(var9.getColumnCount(), var5);
         }

         int var10 = var3 + var5 - 1;
         if (var10 > 16383) {
            short var30 = 16383;
            var5 = var30 - var3 + 1;
         }

         RowCollection var11 = var0.getRows();
         if (var6) {
            Row var12 = var11.get(var2);
            if (var12 != null && var12.getIndex() > var2) {
               ;
            }

            for(int var13 = 0; var13 < var5; ++var13) {
               Cell var14 = var12.get(var3 + var13);

               try {
                  var14.setValue(var9.getColumnName(var13 + 1));
               } catch (Exception var29) {
                  throw new CellsException(6, "", var29);
               }
            }

            ++var2;
         }

         int var31 = 0;
         Timestamp var32 = null;
         Style var33 = var0.h().getWorkbook().createStyle();
         if (var7 != null) {
            try {
               var33.setCustom(var7);
            } catch (Exception var28) {
               throw new CellsException(6, "", var28);
            }
         }

         String var15 = null;

         for(boolean var16 = false; var1.next() && var2 <= 1048575 && (var4 <= 0 || var31 != var4); ++var2) {
            Row var17 = var11.get(var2);
            if (var17 != null && var17.getIndex() > var2) {
               ;
            }

            for(int var18 = 0; var18 < var5; ++var18) {
               Cell var19 = var17.get(var3 + var18);
               if (var19 == null) {
                  var19 = var17.c(var3 + var18);
               }

               int var34 = var9.getColumnType(var18 + 1);
               switch(var34) {
               case -6:
               case -5:
               case 4:
               case 5:
                  try {
                     var19.setValue(var1.getInt(var18 + 1));
                     break;
                  } catch (Exception var27) {
                     throw new CellsException(6, "", var27);
                  }
               case 0:
                  var19.e();
                  break;
               case 2:
               case 3:
               case 6:
               case 7:
               case 8:
                  try {
                     var19.setValue(var1.getDouble(var18 + 1));
                     break;
                  } catch (Exception var26) {
                     throw new CellsException(6, "", var26);
                  }
               case 16:
                  try {
                     var19.setValue(var1.getBoolean(var18 + 1));
                     break;
                  } catch (Exception var25) {
                     throw new CellsException(6, "", var25);
                  }
               case 91:
               case 92:
               case 93:
                  var32 = var1.getTimestamp(var18 + 1);
                  if (var32 != null) {
                     Calendar var20 = Calendar.getInstance();
                     var20.setTime(var32);

                     try {
                        var19.setValue(var20);
                     } catch (Exception var24) {
                        throw new CellsException(6, "", var24);
                     }
                  } else {
                     var19.e();
                  }

                  if (var7 != null) {
                     try {
                        var19.setStyle(var33);
                     } catch (Exception var23) {
                        throw new CellsException(6, "", var23);
                     }
                  }
                  break;
               default:
                  var15 = var1.getString(var18 + 1);

                  try {
                     var19.setValue(var15);
                  } catch (Exception var22) {
                     throw new CellsException(6, "", var22);
                  }
               }
            }

            ++var31;
         }

         return var31;
      } else {
         return 0;
      }
   }

   public static int a(Cells var0, ResultSet var1, int var2, int var3, boolean var4, String var5, boolean var6) throws SQLException {
      return a(var0, var1, var2, var3, -1, -1, var4, var5, var6);
   }
}
